<?php

namespace App\Http\Middleware;
use App\Common\model\VerifyAdminToken;
use Closure;
use Illuminate\Http\Request;

class VerifyAdmin
{
    use VerifyAdminToken;
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $token = $request->header('Authorization');
        if (!$token){
            return response()->json([
                'code'=>9001,
                'msg'=>"验证失败..."
            ]);
        }
        //token 是否过期
        $result = $this->checkToken($token);
        if (!$result){
            return response()->json([
                'code'=>9001,
                'msg'=>"验证失效或者登陆过期..."
            ]);
        }
        return $next($request);
    }

    /*
     *
     * */
}
